package com.lianjinsu.shop.controller;

import com.lianjinsu.shop.controller.vo.Response;
import com.lianjinsu.shop.entity.Shop;
import com.lianjinsu.shop.service.ShopService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

@RequiredArgsConstructor
@RestController
@RequestMapping(value = "Noerify")
public class ShopController {

    private final ShopService shopService;

    @PostMapping("insertGoods")
    Response<Boolean> insertGoods(@RequestBody Shop shop) {
        return Response.ok(shopService.insertGoods(shop));
    }

    @GetMapping("removeById/{id}")
    Response<Boolean> removeById(@PathVariable int id) {
        return Response.ok(shopService.removeById(id));
    }

    @GetMapping("increaseStock/{id}/{stock}")
    Response<Boolean> increaseStock(@PathVariable int id, @PathVariable int stock) {
        return Response.ok(shopService.increaseStock(id, stock));
    }

    @GetMapping("hot/{id}")
    Response<Boolean> hot(@PathVariable int id) {
        return Response.ok(shopService.hotOrNot(id, true));
    }

    @GetMapping("hotNot/{id}")
    Response<Boolean> hotNot(@PathVariable int id) {
        return Response.ok(shopService.hotOrNot(id, false));
    }

    @GetMapping("searchByType")
    Response<List<Shop>> searchByType(@RequestParam String type) {
        return Response.ok(shopService.searchByType(type));
    }

    @GetMapping("allTags")
    Response<Set<String>> allTags() {
        return Response.ok(shopService.allTags());
    }

    @GetMapping("selectByTags")
    Response<List<Shop>> selectByTags(@RequestParam Set<String> tags) {
        return Response.ok(shopService.selectByTags(tags));
    }

    @GetMapping("getHotShopList")
    Response<List<Shop>> getHotShopList() {
        return Response.ok(shopService.hotList());
    }

    @PostMapping("getShopList")
    Response<List<Shop>> getShopList() {
        return Response.ok(shopService.shopList());
    }

    @PostMapping("getShopDetail/{shopId}")
    Response<Shop> getShopDetail(@PathVariable int shopId) {
        return Response.ok(shopService.shopDetail(shopId));
    }

    @GetMapping("searchShopDetail")
    Response<List<Shop>> searchShopDetail(@RequestParam String search) {
        return Response.ok(shopService.shopList(search));
    }
}
